<?php
class XA_Slug {

	public static function get($text, $length = 1024, $delimiter = '-') {
		$text = strtr(mb_strtolower($text, 'UTF-8'), array('ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z'));
		$text = preg_replace('/[^0-9a-z]/', ' ', $text);
		$count = 0;
		do {
			$text = str_replace('  ',  ' ',  $text, $count);
		} while ($count);
		$text = str_replace(' ', $delimiter, trim(substr($text, 0, $length)), $count);
		return $text;
	}
}
